var t = getApp(), e = 0, a = 0, s = void 0, i = 0, o = require("../../../utils/qqmap-wx-jssdk.min.js"), n = void 0;

Page({
    data: {
        userInfo: {},
        hasUserInfo: !1,
        canIUse: wx.canIUse("button.open-type.getUserInfo"),
        sessionKey: "",
        uid: "",
        goLogin: !1,
        type: 0,
        xueli: "专科",
        mid01: "材料与能源大类"
    },
    onLoad: function() {
        var e = this, a = this;
        this.getJobList(0), n = new o({
            key: "Z3HBZ-VX3CP-PQVDI-LMW43-7PQB6-SWFFE"
        }), wx.getLocation({
            type: "wgs84",
            isHighAccuracy: !0,
            success: function(t) {
                wx.setStorageSync("latitude", t.latitude), wx.setStorageSync("longitude", t.longitude), 
                a.getLocal(t.latitude, t.longitude);
            },
            fail: function() {
                wx.setStorageSync("position", "北京");
            }
        }), wx.login({
            success: function(e) {
                if ("login:ok" == e.errMsg) var s = e.code;
                s && wx.request({
                    url: t.globalData.request_url + "api/zhiweiku/getUserInfo.php",
                    method: "POST",
                    data: {
                        code: s,
                        province: "国家"
                    },
                    header: {
                        "content-type": "application/x-www-form-urlencoded"
                    },
                    success: function(t) {
                        200 == t.data.code && a.setData({
                            session_key: t.data.session_key,
                            openId: t.data.openid,
                            uid: t.data.uid
                        });
                    }
                });
            }
        });
        var s = wx.getStorageSync("hasUserInfo"), i = wx.getStorageSync("phone");
        s || i || a.setData({
            goLogin: !0
        }), t.globalData.userInfo ? this.setData({
            userInfo: t.globalData.userInfo,
            hasUserInfo: !0
        }) : this.data.canIUse ? t.userInfoReadyCallback = function(t) {
            e.setData({
                userInfo: t.userInfo,
                hasUserInfo: !0
            });
        } : wx.getUserInfo({
            success: function(a) {
                t.globalData.userInfo = a.userInfo, e.setData({
                    userInfo: a.userInfo,
                    hasUserInfo: !0
                });
            }
        });
    },
    getJobList: function(e) {
        var a = this;
        wx.showLoading({
            title: "加载中"
        }), wx.request({
            url: t.globalData.request_url + "/api/zhiweiku/getZySearch.php",
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            data: {
                xueli: e
            },
            success: function(t) {
                200 == t.data.code && a.setData({
                    list: t.data.list,
                    cid: 0,
                    scroll: 0,
                    mid01: t.data.list.one[0].xkml
                }), wx.hideLoading();
            }
        });
    },
    searchJobList: function(e, a) {
        var s = this;
        wx.showLoading({
            title: "加载中"
        }), wx.request({
            url: t.globalData.request_url + "api/zhiweiku/getZhuanye.php",
            data: {
                zhuanye: e,
                act: "getall",
                xueli: s.data.type
            },
            method: "post",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                200 == t.data.code && (s.setData({
                    list: t.data.list,
                    cid: 0,
                    search: !0
                }), "" != t.data.list.one && s.setData({
                    mid01: t.data.list.one[0].xkml
                })), wx.hideLoading();
            }
        });
    },
    changeType: function(t) {
        i = parseInt(t.currentTarget.dataset.index);
        var e = t.currentTarget.dataset.name;
        this.setData({
            type: i,
            scroll_l: 0,
            xueli: e
        }), 1 == this.data.search ? this.searchJobList(this.data.keywords, this.data.type) : this.getJobList(this.data.type);
    },
    watchInput: function(t) {
        "" == t.detail.value && (this.setData({
            search: !1
        }), this.getJobList(this.data.type));
    },
    search: function(t) {
        var e = t.detail.value;
        this.setData({
            keywords: e
        }), this.searchJobList(this.data.keywords, this.data.type), 0 == this.data.type || this.data.type;
    },
    getChildren: function(t) {
        var e = t.currentTarget.dataset.index, a = t.currentTarget.dataset.key;
        this.setData({
            cid: e,
            scroll: 0,
            mid01: a
        }), 0 == this.data.type || this.data.type;
    },
    touchStart: function(t) {
        a = t.touches[0].pageX, s = setInterval(function() {
            e++;
        }, 100);
    },
    touchEnd: function(t) {
        clearInterval(s), e = 0;
        var o = t.changedTouches[0].pageX;
        o - a <= -90 && e < 20 && (parseInt(i += 1), i >= 3 && (i = 0), this.setData({
            type: i
        }), 1 == this.data.search ? this.searchJobList(this.data.keywords, this.data.type) : this.getJobList(this.data.type)), 
        o - a >= 90 && e < 20 && ((i -= 1) <= -1 && (i = 2), this.setData({
            type: i
        }), 1 == this.data.search ? this.searchJobList(this.data.keywords, this.data.type) : this.getJobList(this.data.type));
    },
    onShareAppMessage: function(t) {
        return {
            title: "国考小助手",
            path: "/pages/index/index"
        };
    },
    getLocal: function(t, e) {
        n.reverseGeocoder({
            location: {
                latitude: t,
                longitude: e
            },
            success: function(t) {
                var e = t.result.ad_info.province.replace("市", ""), a = t.result.ad_info.city.replace("市", "");
                e = (e = (e = (e = (e = (e = e.replace("省", "")).replace("壮族自治区", "")).replace("回族自治区", "")).replace("维吾尔自治区", "")).replace("自治区", "")).replace("特别行政区", ""), 
                wx.setStorageSync("position", e), wx.setStorageSync("city", a);
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getPhoneNumber: function(e) {
        var a = this, s = e.currentTarget.dataset.url;
        "getPhoneNumber:ok" == e.detail.errMsg && wx.request({
            url: t.globalData.request_url + "api/zhiweiku/getSelf.php",
            data: {
                encryptedData: e.detail.encryptedData,
                iv: e.detail.iv,
                sessionKey: a.data.session_key,
                act: "up_mobile",
                province: "国家",
                uid: a.data.uid
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            method: "post",
            success: function(t) {
                wx.setStorageSync("hasUserInfo", "1"), wx.setStorageSync("openId", a.data.openId), 
                wx.setStorageSync("phone", t.data.phoneNumber), a.setData({
                    goLogin: !1
                }), s && wx.navigateTo({
                    url: s
                });
            },
            fail: function() {
                a.wxlogin();
            }
        }), "getPhoneNumber:fail user deny" == e.detail.errMsg && wx.showModal({
            title: "提示",
            content: "为了更好的用户体验请先授权"
        });
    }
});